package com.jiang.books.service.jpa;

import com.google.common.collect.Lists;
import com.jiang.books.domain.Profile;
import com.jiang.books.repository.IProfileRepository;
import com.jiang.books.service.IProfileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;

@Service
@Transactional
public class ProfileSpDataService implements IProfileService {

    @Autowired
    IProfileRepository repository;

    @PersistenceContext
    public EntityManager em;

    @Override
    public List<Profile> findAll() {
        Iterable<Profile> ugs = repository.findAll();
        return Lists.newArrayList(ugs);
    }

    @Override
    public Profile findById(Long id) {
        return repository.findOne(id);
    }

    @Override
    @Transactional(readOnly = false)
    public Profile save(Profile profile) {
        return repository.save(profile);
    }

    @Override
    @Transactional(readOnly = false)
    public void delete(Profile profile) {
        repository.delete(profile);
    }
    
}